﻿using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;

namespace Model.CursorConvert
{
    public class CursorHelper
    {
        private static Dictionary<Cursor, string> _dicCursorName =null;

        public static Dictionary<string, Cursor> DicNameCursor { get; } = new Dictionary<string, Cursor>()
        {
            {"Cursors.AppStarting", Cursors.AppStarting},
            {"Cursors.Arrow",Cursors.Arrow},
            {"Cursors.Cross",Cursors.Cross            },
            {"Cursors.Default", Cursors.Default       },
            {"Cursors.Hand",Cursors.Hand              },
            {"Cursors.Help", Cursors.Help             },
            {"Cursors.HSplit", Cursors.HSplit     },
            {"Cursors.IBeam", Cursors.IBeam      },
            {"Cursors.No", Cursors.No       },
            {"Cursors.NoMove2D", Cursors.NoMove2D  },
            {"Cursors.NoMoveHoriz", Cursors.NoMoveHoriz },
            {"Cursors.NoMoveVert", Cursors.NoMoveVert },
            {"Cursors.PanEast", Cursors.PanEast    },
            {"Cursors.PanNE", Cursors.PanNE      },
            {"Cursors.PanNorth", Cursors.PanNorth   },
            {"Cursors.PanNW", Cursors.PanNW      },
            {"Cursors.PanSE", Cursors.PanSE     },
            {"Cursors.PanSouth", Cursors.PanSouth  },
            {"Cursors.PanSW", Cursors.PanSW      },
            {"Cursors.PanWest", Cursors.PanWest    },
            {"Cursors.SizeAll", Cursors.SizeAll    },
            {"Cursors.SizeNESW", Cursors.SizeNESW   },
            {"Cursors.SizeNS", Cursors.SizeNS    },
            {"Cursors.SizeNWSE", Cursors.SizeNWSE  },
            {"Cursors.SizeWE", Cursors.SizeWE    },
            {"Cursors.UpArrow", Cursors.UpArrow    },
            {"Cursors.VSplit", Cursors.VSplit    },
            {"Cursors.WaitCursor", Cursors.WaitCursor  },
        };

        public static Dictionary<Cursor, string> DicCursorName
        {
            get
            {
                if (_dicCursorName==null)
                {
                    _dicCursorName = new Dictionary<Cursor, string>();
                    foreach (var nameCursor in DicNameCursor)
                    {
                        _dicCursorName[nameCursor.Value] = nameCursor.Key;
                    }
                }

                return _dicCursorName;
            }
        }

        public static string Name(Cursor cursor)
        {
            string strRet ;
            if (DicCursorName.TryGetValue(cursor,out strRet))
            {
                return strRet;
            }
            return DicCursorName[Cursors.Default];
        }

        public static Cursor GetCursor(string name)
        {
            Trace.WriteLine(name);

            Cursor ret;
            if (DicNameCursor.TryGetValue(name, out ret))
            {
                return ret;
            }
            return Cursors.Default;
        }
    };
}
